      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/product/index">商品管理</a></li>
            <li class="active">查看库存</li>
          </ol>
          <div class="row margin-bottom-5">
             <div class="col-md-12">
            	<a class="btn btn-primary" id="shelve_btn" href="<?php echo site_url('product/shelves')?>">查看下架商品</a>
            	<a class="btn btn-primary" id="short_btn" href="<?php echo site_url('product/shorts')?>">查看补货中商品</a>
            </div>
           </div>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <h4 class="margin-bottom-15">商品库存列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>商品名称</th>
                      <th>操作</th>
                      <th>库存量2</th>
                      <th>单位</th>
                      <th>进货价</th>    
                      <th>总价</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($products as $item):?>
                    <tr>
                      <td><?php echo $item['name'].'-'.$item['description'];?></td>
                      <td>  
                      		<input style="width:40px" type="text" id="sum<?php echo $item['id'];?>" value="1">
                      	  	<button class="send" data-id="<?php echo $item['id'];?>" >推送</button>
                      	  	 <a href="javascript:void(0)" class="btn btn-link hidepro" data-id="<?php echo $item['id'];?>" >下架</a>
                      	  	 <span id="state<?php echo $item['id'];?>">
                      	  	 	<?php if($item['short']==0){ ?>
									 <a href="javascript:void(0)" class="btn btn-link short" data-id="<?php echo $item['id'];?>" >补货</a>
								<?php }else{?>
									<a href="javascript:void(0)" class="btn btn-link full" data-id="<?php echo $item['id'];?>" >供应</a>
								<?php }?>
							</span>
                      </td>
                      <td><?php echo $item['stock'];?></td>
                      <td><?php echo $item['unit'];?></td>
                      <td><?php echo $item['purprice'];?></td>
                      <td><?php echo $item['purprice']*$item['stock'];?></td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
<script>
	$(document).ready(function() {
		$(".send").click(function() {
			if(confirm("确定要推送吗？"))
			{
			var productid = $(this).attr("data-id");
			var amount = $("#sum"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/exportSupply')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'amount' : amount
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".hidepro").click(function() {
			if(confirm("确定要下架吗？"))
			{
			var productid= $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductstate')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'state':0
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
			}
		});
		$(".short").click(function() {
			if(confirm("确定要补货吗？"))
			{
			var productid= $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductshort')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'short':1
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
						$("#state"+productid).html('<a href="javascript:void(0)" class="btn btn-link full" data-id="'+productid+'" >供应</a>');
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".full").click(function() {
			if(confirm("确定要供应吗？"))
			{
			var productid= $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductshort')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'short':0
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
						$("#state"+productid).html('<a href="javascript:void(0)" class="btn btn-link short" data-id="'+productid+'" >补货</a>');
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		
	}); 
</script>